home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / dev / e / doomwad.lha / DoomWAD.doc next >
Text File  |  1998-03-15  |  7KB  |  240 lines

  1.  
  2.                           Peter Gordon Presents
  3.  
  4. ------------------------------- DOOMWAD.M ----------------------------------
  5.  
  6.  
  7.          An Amiga E module to load and decode Doom 1 & 2 .WAD files.
  8.          
  9.  
  10. 1. INTRODUCTION
  11.  
  12. DoomWAD.m was written because I wanted to write a level editor for Doom
  13. basically :). I started work on it but the actual level format of Doom
  14. was far to complex for me to get my head around :(
  15.  
  16. I'm releasing the work I've done already so that other people can write
  17. Doom editors/utils for the Amiga. So go to it :)
  18.  
  19.  
  20. 2. WHATS IN THE ARCHIVE?
  21.  
  22. Well, this:
  23.  
  24. modules/doomwad.m       - My routines for opening/decoding doom wad files
  25. modules/doomwad.e       - Source code for said module
  26. DoomSpec/DmSpec16.txt   - The (very nearly) complete file format of Doom 1
  27.                           and 2 .WADs. Be careful, this is real brain
  28.                           death stuff :)
  29. Examples/endoomview     - A viewer of ENDOOM lumps (the messages that come
  30.                           up when you quit doom)
  31. Examples/endoomview.e   - Source code for endoomview
  32. Examples/waddir         - A util to show all the "lumps" in a doom wad
  33. Examples/waddir.e       - Source code for waddir
  34. DoomWAD.doc             - This file
  35.  
  36.  
  37. 3. DISTRIBUTION, USAGE AND DISCLAIMER
  38.  
  39. The author provides no warranties of any kind either express or implied.
  40. Use all this stuff at your own risk.
  41.  
  42. You can do what the hell you like with these files, with one condition,
  43. you credit me as the original author of the routines.
  44.  
  45.  
  46. 4. PROGRAMMING STUFF
  47.  
  48. If you dont understand any of this stuff, a quick browse through DmSpec16.txt
  49. should help :)
  50.  
  51. OK, so whats in DoomWAD.m? Well, first off there is a whole load of
  52. constants that give more readable names to all the "things".
  53. A thing is a sprite, or a player start, or a bonus pickup etc. etc.
  54.  
  55. It also has the following routines:
  56.  
  57. ----------------------------------------------------------------------------
  58.  
  59. NAME  openwad
  60.  
  61. USAGE handle := openwad( filename )
  62.       |                  |
  63.       PTR TO wadhandle   PTR TO CHAR
  64.       
  65. This routine returns a pointer to a WADHandle structure, which is:
  66.  
  67. OBJECT wadhandle
  68.   dosh,               -> The AmigaDOS handle to the actual .WAD file
  69.   iwad,               -> TRUE if the WAD is an IWAD, false if its a PWAD
  70.   numlumps,           -> Number of "lumps" in the wad
  71.   dirstrt             -> Offset to the start of the directory
  72. ENDOBJECT
  73.  
  74. It will return NIL if it cannot open the wad.
  75.  
  76. ----------------------------------------------------------------------------
  77.  
  78. NAME  closewad
  79.  
  80. USAGE closewad( handle )
  81.                 |
  82.                 PTR TO wadhandle
  83.                 
  84. Closes a wad opened with openwad()
  85.  
  86. ----------------------------------------------------------------------------
  87.  
  88. NAME  readentry
  89.  
  90. USAGE readentry( offset, handle, dirblock )
  91.                          |       |
  92.                          |       PTR TO dirblock
  93.                          PTR TO wadhandle
  94.                          
  95. This routine will fill out a dirblock object from the offset specified.
  96. A dirblock object is:
  97.  
  98. OBJECT dirblock
  99.   offset,               -> Lump offset from start of WAD
  100.   size,                 -> Size of lump
  101.   name[8]:ARRAY OF CHAR -> name of lump
  102. ENDOBJECT
  103.  
  104. So, to read the first entry in the wad directory into a previously allocated
  105. dirblock structure called dbk, using an open wadhandle called wdh, you
  106. would do:
  107.  
  108. readentry(0, wdh, dbk)
  109.  
  110. To read the next entry, you would do:
  111.  
  112. readentry(16, wdh, dbk)
  113.  
  114. (each direntry is 16 bytes long).
  115.  
  116.  
  117. NOTES 
  118.  
  119. This routine will never fail. If you give it an offset to a location that
  120. isnt a direntry, the dirblock will be filled with garbage.
  121.  
  122. ----------------------------------------------------------------------------
  123.  
  124. NAME  findentry
  125.  
  126. USAGE success, diroffset := findentry( entryname, handle, dirblock)
  127.  
  128. This routine will scan through the wad looking for a specific lump by name.
  129. It will return TRUE in success if it finds it, and FALSE if it doesnt.
  130.  
  131. If success is TRUE, dirblock will be filled out to point to the lump you
  132. were searching for. If for some reason you need to re-read the dirblock,
  133. you can do the following:
  134.  
  135. success, diroffset := findentry('ENDOOM',wdh,dbk)
  136. IF(success)
  137.   
  138.   /*
  139.   ** Do some stuff with the ENDOOM lump
  140.   */
  141.   
  142.   /* Oh no, dirblock has been trashed :-) */
  143.   dbk.offset:=0
  144.   
  145.   /* Find that entry again */
  146.   readentry(diroffset*16,wdh,dbk)
  147. ENDIF
  148.  
  149. ----------------------------------------------------------------------------
  150.  
  151. NAME  readthings()
  152.  
  153. USAGE thinglist := readthings( levelname, handle )
  154.       |                                   |
  155.       PTR TO thing                        PTR TO wadhandle
  156.       
  157. This routine will decode a THINGS lump for a specified level into a big
  158. "list" of thing objects. A thing object is:
  159.  
  160. OBJECT thing
  161.   nextthing:PTR TO thing,     -> Pointer to next thing in list, or 0
  162.   prevthing:PTR TO thing,     -> Pointer to previous thing in list, or 0
  163.   x:INT,                      -> X position of thing
  164.   y:INT,                      -> Y position of thing
  165.   angle:INT,                  -> Angle of thing
  166.   type:INT,                   -> type of thing (e.g. shotgun, playerstart)
  167.   options:INT                 -> options
  168. ENDOBJECT
  169.  
  170. So, for a Doom 1 WAD, you could do:
  171.  
  172. thinglist:=readthings('E1M1',wdh)
  173. IF(thinglist)
  174.   current_thing:=thinglist
  175.   WHILE(current_thing<>0)
  176.     WriteF('Thing \d at position (\d,\d)\n',current_thing.type,current_thing.x,current_thing.y)
  177.     current_thing:=current_thing.nextthing
  178.   ENDWHILE
  179.   freethings(thinglist)
  180. ENDIF
  181.  
  182. Which would display the position and type of all the things on episode 1
  183. map 1.
  184.  
  185. ----------------------------------------------------------------------------
  186.  
  187. NAME  freethings
  188.  
  189. USAGE freethings( thinglist )
  190.                   |
  191.                   PTR TO thing
  192.                   
  193. This routine frees a thinglist allocated by readthings()
  194.  
  195. ----------------------------------------------------------------------------
  196.  
  197. NAME  motoword
  198.  
  199. USAGE motorola_word := motoword( intel_word )
  200.  
  201.       OR
  202.       
  203.       intel_word := motoword( motorola_word )
  204.       
  205. Because all the words in a Doom wad use intel "Little Endian" words, we
  206. need to convert them before we play with them. Any intel word passed to
  207. this routine will be returned as a motorola word, and vice versa.
  208.  
  209. ----------------------------------------------------------------------------
  210.  
  211. NAME  motolong
  212.  
  213. USAGE motorola_long := motolong( intel_long )
  214.  
  215.       OR
  216.       
  217.       intel_long := motoword( motorola_long )
  218.       
  219. Same as motoword() but for longwords
  220.  
  221.  
  222. 5. USING THE EXAMPLES
  223.  
  224. To use Endoomview or Waddir, simply specify a .WAD, e.g:
  225.  
  226. endoomview hd1:Games/doom/doomu.wad
  227. waddir hd1:games/doom2/doom2.wad
  228.  
  229. If you have a font called ansi.font in your fonts dir, endoomview will
  230. use it to get all the proper IBM chars, otherwise it'll just use topaz.
  231.  
  232. 6. THATS ALL FOLKS
  233.  
  234. I cant be arsed to write any more gibberish :) If you improve doomwad.m,
  235. or need help using it, e-mail me at:
  236.  
  237. the.moosuck@borghome.demon.co.uk
  238.  
  239. PLEASE send me your improved doomwad.e source codes if you make any :)
  240.